<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
</head>
<body class="page-header-fixed page-sidebar-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<div class="page-container">
    <div class="page-sidebar-wrapper"><jsp:include page="../common/menu.jsp"/></div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <form class="form-horizontal form-row-seperated" action="${path}/article/upd">
                        <div class="portlet box purple">
                            <div class="portlet-title">
                                <div class="caption">
                                    <i class="fa fa-shopping-cart"></i>添加文本消息
                                </div>
                                <div class="actions btn-set">
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="tabbable">
                                    <div class="tab-content no-space">
                                        <div class="tab-pane active" id="tab_general">
                                            <div class="form-body">
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">标题:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="title" name="title"
                                                               class="form-control measure-input" datatype="*1-80"
                                                               value="${data.title}"/>
                                                    </div>
                                                    <div class="col-md-5">
                                                        &nbsp;可输入<b><span id="title_len">80</span></b> 个字符
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">作者(选填):
                                                    </label>

                                                    <div class="col-md-5">
                                                        <input type="text" id="author" name="author"
                                                               class="form-control" datatype="*1-30"
                                                               value="${data.author}"/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">内容:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-8">
                                                        <jsp:include page="../common/editor.jsp"/>
                                                        <input id="context" type="hidden" name="context" datatype="*">
                                                        <%-- <textarea cols="80" id="context" name="context" datatype="*" rows="10">${data.context}</textarea> --%>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="portlet-title">
                                <div class="actions btn-set">
                                    <a href="javascript:history.go(-1);" class="btn default"><i
                                            class="fa fa-angle-left"></i> 返回</a>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" id="id" name="id" value="${data.id}">
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script>
    var operType = '${operType}';
    var editor, form;
    jQuery(document).ready(function () {
        form = $("form").Validform({
            tiptype: 3,
            postonce: true,
            showAllError: true,
            callback: function (data) {
                if (data && data.statusCode === 200) {
                    /* var id = $("#id");
                     if(!id.val())
                     id.val(data.id);
                     if(confirm("保存成功，是否跳转到智库管理页面？")) */
                    window.location.href = _path + "/article/init/" + operType + "/" + operType;
                } else {
                    alert("保存失败！");
                }
            }
        });
        $("button[id='btnSave']").click(function (e) {
// 		var context = editor.getData();
            var context = $('#editor').html();
            if (!/[\w\W]+/.test(context)) {
                alert("内容不能为空");
                return;
            }
            $("#context").val(context);
            form.ajaxPost(false, true, _path + "/article/save");
        });
//     editor = CKEDITOR.replace('context');
    });
</script>
</body>
</html>